#!python
from binary_helpers import *

""" array.py
Create a binary file with an array of floats, an array of int, an array of string
array.xml and this file must ALWAYS be in sync
"""

FILE = "array.bin"
MODEL = "array.xml"
VALUES = [
        10,
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
        5,
        0.0, 0.1, 0.2, 0.3, 0.4,
        5,
        bstr("hello", 32), bstr("coucou", 32), bstr("hola", 32), bstr("good morning", 32), bstr("konichiwa", 32),
        6,
        3.14 , 0 , bstr("hello", 32), 2 , 1 ,2 ,
        4.14 , 1 , bstr("hello", 32), 2 , 3 ,4 ,
        5.14 , 2 , bstr("hello", 32), 2 , 5 ,6 ,
        6.14 , 3 , bstr("hello", 32), 3 , 7 ,8, 9,
        7.14 , 4 , bstr("hello", 32), 2 , 10 ,11,
        8.14 , 5 , bstr("hello", 32), 2 , 12 ,14,
        ]

def main():
    """
    Output a binary file with 

    """
    fd = open(FILE, mode='wb') 

    int_array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    int_to_bin(fd, len(int_array))
    for i in int_array:
        int_to_bin(fd, i)

    float_array = [0.0, 0.1, 0.2, 0.3, 0.4]
    int_to_bin(fd, len(float_array))
    for f in float_array:
        float_to_bin(fd, f)

    string_array = [ "hello", "coucou", "hola", "good morning", "konichiwa" ]
    int_to_bin(fd, len(string_array))
    for string in string_array:
        string_to_bin(fd, string, 32)

    mixed_array = [ 
            [3.14 , 0 , "hello", 2 , [ 1, 2 ] ],
            [4.14 , 1 , "hello", 2 , [ 3, 4 ] ],
            [5.14 , 2 , "hello", 2 , [ 5, 6 ] ],
            [6.14 , 3 , "hello", 3 , [ 7, 8, 9 ] ],
            [7.14 , 4 , "hello", 2 , [ 10, 11 ] ],
            [8.14 , 5 , "hello", 2 , [ 12, 14 ] ],
            ]	
    int_to_bin(fd, len(mixed_array))
    for mixed in mixed_array:
        f, i, s, i2, a = mixed 
        float_to_bin(fd, f)	
        int_to_bin(fd, i)	
        string_to_bin(fd, s, 32)	
        int_to_bin(fd, i2)	
        for e in a:
            int_to_bin(fd, e)	

    fd.close()


if __name__ == "__main__":
    main()

